package com.example.baselibrary.Utils;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.hardware.camera2.params.Face;
import android.util.AttributeSet;
import android.view.View;


public class FaceMasks extends View {

    private Paint localPaint;
    private RectF rectPrc;
    private static OutFace outFace;


    public FaceMasks(Context context, AttributeSet atti) {
        super(context, atti);
        localPaint = new Paint();
        localPaint.setColor(0xff248FAF);
        localPaint.setStrokeWidth(5);
        localPaint.setStyle(Paint.Style.STROKE);
    }


    public void setFacePar(RectF rect) {
        if (rect.left != 0) {
            float left = rect.left * 2 - 50;
            float top = rect.top * 2 - 50;
            float right = rect.left * 2 + 350;
            float botton = rect.top * 2 + 350;

            if (left < 0) {
                left = 0;
            }
            if (top < 0) {
                top = 0;
            }
            if (right > 1040) {
                right = 940;
            }
            if (botton > 1280) {
                botton = 980;
            }

            if (right > 940) {
                outFace.faceOut();
            }
            if (botton > 980) {
                outFace.faceOut();
            }
            rectPrc = new RectF(left, top, right, botton);
        } else {
            rectPrc = rect;
        }
//        invalidate();
        postInvalidate();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        // 对另外一个方法  画框
        if (rectPrc == null) {
            return;
        } else {
//            localPaint.setColor(0xff248FAF);
//            canvas.drawRect(rectPrc, localPaint);
            localPaint.setColor(Color.GREEN);
            rectPrc = new RectF(100, 100, 940, 1130);
            canvas.drawRect(rectPrc, localPaint);
//            System.out.println("zyf" + "绘制人脸");
        }
    }

    public static void setOutFaceListener(OutFace outFaceListener) {
        outFace = outFaceListener;
    }

}
